// Copyright (C) 2025 Kumo inc.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//

#include "test.hpp"

namespace rothar
{
   // clang-format off
   struct A : one< 'a' > {};
   struct B : one< 'b' > {};
   struct C : one< 'c' > {};
   struct BCB : seq< B, C, B > {};
   struct ABCBA : seq< A, BCB, A > {};
   // clang-format on

   template< typename >
   struct my_action
   {};

   template<>
   struct my_action< A >
   {
      static void apply0( int& a, int& /*b*/, int& /*c*/ )
      {
         ++a;
      }
   };

   template<>
   struct my_action< B >
      : disable_action
   {
      static void apply0( int& /*a*/, int& b, int& /*c*/ )
      {
         ++b;
      }
   };

   template<>
   struct my_action< C >
      : enable_action
   {
      static void apply0( int& /*a*/, int& /*b*/, int& c )
      {
         ++c;
      }
   };

   void unit_test()
   {
      memory_input<> in( "abcba", "" );
      int a = 0;
      int b = 0;
      int c = 0;
      const auto result = parse< ABCBA, my_action >( in, a, b, c );
      ROTHAR_PEGTL_TEST_ASSERT( result );
      ROTHAR_PEGTL_TEST_ASSERT( a == 2 );
      ROTHAR_PEGTL_TEST_ASSERT( b == 0 );
      ROTHAR_PEGTL_TEST_ASSERT( c == 1 );
   }

}  // namespace rothar

#include "main.hpp"
